<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>51微贷</title>
		<link rel="stylesheet" type="text/css" href="../css/reset.css">
		<link rel="stylesheet" type="text/css" href="../css/common.css">
		<link rel="stylesheet" type="text/css" href="../css/icomoon/style.css">
		<link rel="stylesheet" type="text/css" href="../css/listloading.base.css">
		<link rel="stylesheet" type="text/css" href="../css/listloading.min.css">
		<script type="text/javascript" src="../js/rem.js"></script>
		<script type="text/javascript" src="../js/zepto.min.js"></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/require.js"></script>
		<script type="text/javascript" src="../js/listloading.iconfont.js"></script>
	</head>

	<body>
		<h3 class="header">理财</h3>
		<div class="m-invest">
			<div id="main" class="">
				<!--<div class="recommend">
					<h3>推荐理财</h3>
				</div>-->
				<div class="project-list"></div>
			</div>
			<div class="select hide" id="select">
				<h3>期限</h3>
				<ul class="select-list clearfix" id="date-line">
					<li class="f-fl">7-15天</li>
					<li class="f-fr">16天-1个月</li>
					<li class="f-fl">2-3个月</li>
					<li class="f-fr">4-6个月</li>
					<li class="f-fl">7-12个月</li>
					<li class="f-fr">12个月以上</li>
				</ul>
				<h3>利率</h3>
				<ul class="select-list clearfix" id="rate">
					<li class="f-fl">5%-9%</li>
					<li class="f-fr">9%-11%</li>
					<li class="f-fl">11%-13%</li>
					<li class="f-fr">13%以上</li>
				</ul>
				<div class="btn-box clearfix">
					<a href="javascript:;" class="btn reset">重置</a>
					<a href="javascript:;" class="btn confirm">筛选</a>
				</div>
			</div>
		</div>

		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript">
			require(['iscroll', 'listloading', 'Circles', 'encryption'], function() {
				var md5 = require('encryption');
				var Listloading = require('listloading');
				var Circles = require('Circles');
				var page_index = 1,
					page_size = 5,
					page_count = 10;
				var clientWidth = document.documentElement.clientWidth;
				var canvasWidth = Math.floor(clientWidth * 124 / 750);
				var radius = canvasWidth / 2;
				var width = Math.floor(clientWidth * 8 / 750);

				$('.m-invest, .listloadingClass').height($(window).height() - 20);

				var List = function(item) {
					var result = '';
					result += '<div class="project" data-id="' + item.id + '">';
					result += '<h4><span class="periods">' + item.name + '</span><span class="num f-fr">' + item.bid_count + '笔购买</span></h4>';
					result += '<div class="info clearfix">';
					result += '<p><span class="percent"><span>' + item.rate + '</span>%</span>';
					result += '<span>预期收益</span></p>';
					result += '<p class="center"><span class="date-line"><span>' + item.dead_line + '</span>' + item.date_type + '</span><span>' + item.credit_type + '</span></p>';
					result += '<p class="right f-pr">';
					if(item.percent == 100) {
						var content = '已满标'; //状态==3
						if(item.status == 5) {
							content = '还款中';
						} else if(item.status == 6) {
							content = '完成';
						}
						result += '<span class="complete f-pa"><span class="child f-pa">' + content + '</span></span>';
					} else {
						result += '<span class="circle" id="circle-' + item.id + '"></span></p>';
					}
					result += '</div></div>';

					$('.project-list').append(result);

					Circles.create({
						id: 'circle-' + item.id,
						radius: radius,
						value: item.percent,
						maxValue: 100,
						width: width,
						text: '投',
						colors: ['#edecef', '#20adff'],
						duration: 500,
						wrpClass: 'circles-wrp',
						textClass: 'circles-text',
						valueStrokeClass: 'circles-valueStroke',
						maxValueStrokeClass: 'circles-maxValueStroke',
						styleWrapper: true,
						styleText: true
					});
					$('.circles-text').css({
						'font-size': '0.5rem',
						'color': '#20adff'
					});
				}

				var creditList = function(cb, flag, page_index, page_size) {
					if(flag) {
						return cb(flag);
					}
					mui.ajax(base + 'credit/pagelist', {
						type: 'get',
						data: {
							'page_index': page_index,
							'page_size': page_size
						},
						dataType: 'json',
						headers: sign(md5),
						success: function(data) {
							var list = data.list,
								page_index = data.page_index,
								page_count = data.page_total;
							if(data.page_index == 1) {
								$('.project-list').empty();
							}
							for(var i = 0, len = list.length; i < len; i++) {
								List(list[i]);
							}
							cb(flag);

						},
						error: function(data) {
							console.error(JSON.stringify(data));
						}
					});
				};

				var listloading = new Listloading('.m-invest', {
					disableTime: true,
					pullUpAction: function(cb) {
						var flg = false;
						if(page_index + 1 > page_count) {
							flg = true;
						} else {
							page_index++;
						}
						return creditList(cb, flg, page_index, page_size);
					},
					pullDownAction: function(cb, flg) {
						page_index = 1;
						return creditList(cb, false, page_index, page_size);
					},
					Realtimetxt: '官人不要，请放开我！',
					loaderendtxt: '我是有底线的',
					iscrollOptions: {
						scrollbars: false
					}
				});

				listloading.evt('.project', 'tap', function(dom) {
					var data_id = $(dom).attr('data-id');
					mui.openWindow({
						url: 'project.html',
						extras: {
							credit: data_id
						},
						show: {
							aniShow: 'pop-in', //页面显示动画，默认为”slide-in-right“；
							event: "loaded"
						}
					});
					listloading.refresh();
				});

			});

			require.config({
				paths: {
					'Circles': '../js/circles.min',
					'iscroll': '../js/iscroll.min',
					'listloading': '../js/listloading.min',
					'encryption': '../js/md5.min'
				}
			});
		</script>
	</body>

</html>